define([
    'zepto',
    'underscore',
    'backbone',
    "text!templates/qpay/orderInfo.html",
    "text!templates/qpay/noCard.html",
    "text!templates/qpay/haveCard.html",
    "text!templates/qpay/uploadDebit.html",
    "text!templates/qpay/uploadCreadit.html",
    "text!templates/agreement.html",
    //测试 start
    "text!templates/qpay/addDebitInfo.html",
    "text!templates/qpay/addCreaditInfo.html",
    "text!templates/qpay/limitList.html",
    "text!templates/qpay/addVerify.html",
    "text!templates/qpay/addAgreement.html",
    "text!templates/qpay/unbind.html",
    //测试 end 
    "wTools"

], function ($, _, Backbone, orderInfo, noCard, haveCard, upDebit, upCreadit, agreement, debitInfo, creaditInfo, banLimit, addVerify, addAgreement,unbind) {
    return Backbone.View.extend({
        $el: $main,
        el: $main0,
        isEmpty: true,
        isEmpty01: true,//测试 张迪
        bPass: false,
        isChooseCard: true,
        templateOrderInfo: _.template(orderInfo),
        templateNoCard: _.template(noCard),
        templateHaveCard: _.template(haveCard),
        templateUpDebit: _.template(upDebit),
        templateUpCreadit: _.template(upCreadit),
        templateAgreement: _.template(agreement),
        //测试 start
        templateDebitInfo: _.template(debitInfo),
        templateCreaditInfo: _.template(creaditInfo),
        templateBankLimit: _.template(banLimit),
        templateAddVerify: _.template(addVerify),
        templateAddAgreement: _.template(addAgreement),
        templateUnbind:_.template(unbind),
        //测试 end
        events: {
            "blur #bankCode":"bankTest",
            "input #bankCode":"limitLen",
            "input #verifyNo":"limitLen",
            "touchend #showAgreement": "showAgreement",
            "click #showAgreement": "showAgreement",
            "touchend #closeAgreement": "closeAgreement",
            "click #closeAgreement": "closeAgreement",

            "touchend #getVerify": "getVerify",
            "click #getVerify": "getVerify",
            "touchend #confirm" : "confirm",
            "click #confirm" : "confirm",
            /***张迪 点击‘选择新银行卡’事件 start ***/
            "touchend #chooseCard" : "chooseCard",
            "click #chooseCard" : "chooseCard",
            "touchend #mask_box" : "mask_box",
            "click #mask_box" : "mask_box",
            "touchend #remove_bind" : "remove_bind",
            "click #remove_bind" : "remove_bind",
            "touchend #useNewCard" : "useNewCard",
            "click #useNewCard" : "useNewCard",
            "touchend #choosecard_confirm" : "choosecard_confirm",
            "click #choosecard_confirm" : "choosecard_confirm",
            "click #chooseCard1 .chooseCard1" : "chooseCard1",
            "touchend #limitList" : "limitList",
            "click #limitList" : "limitList",
            "click #closeBankLimit": "closeBankLimit",

            "blur #username":"nameTest",
            "blur #idCard":"idCardTest",
            "blur #phone":"phoneNumTest",
            "blur #iardCvn2":"cvv2NumTest",
            "blur #iardExprDt":"dateNumTest",

            "input #username":"limitLen01",
            "input #idCard":"limitLen01",
            "input #phone":"limitLen01",
            "input #iardCvn2":"limitLen01",
            "input #iardExprDt":"limitLen01",
            "input #verifyNo01":"limitLen01",

            "touchend #getVerify01": "getVerify01",
            "click #getVerify01": "getVerify01",
            "touchend #confirm01" : "confirm01",
            "click #confirm01" : "confirm01",

            
            /***张迪 点击‘选择新银行卡’事件 end   ***/
            
        },

        initialize: function () {
        	console.log("初始化数据："+JSON.stringify(wData) )
        	//$('#bankCode').val(wData.cardList[wData.selectCardIndex].cardBegin + '******' + wData.cardList[wData.selectCardIndex].cardEnd)
            $("#head_back").hide();
            
            if (wData.urlData.token != undefined && wData.urlData.token != "" && wData.urlData.token != null && wData.urlData.token != wData.token) {
                wData.token = wData.urlData.token;
            }
            

            var postData = {
                "token": wData.token
            }, that = this;

            wAjaxForm('getTokenInfo', '' ,postData, function(result){
            	//isBindCard：0未绑卡1绑卡
            	//isUpload：是否上送要素信息0：未上送1：已上送   ------》》》》》是不是没有填写的信息
            	//trxId：商户订单号
            	//userNo：用户号
            	//returnUrl：同步回调地址
                wData.isBindCard = result.tokenInfo.isBindCard;
                wData.isUpload = result.tokenInfo.isUpload;
                wData.trxId = result.tokenInfo.trxId;
                wData.userNo = result.tokenInfo.merUserId;
                wData.returnUrl = result.tokenInfo.returnUrl;

                //2017/11/02 张迪 添加绑卡列表信息 start
                wAjaxForm('queryAuthInfo', '' ,postData, function(res) {
                    res = JSON.parse(res);
                    if(res.sysRtnDesc == '处理成功'){
                       console.log("查询cardList值："+JSON.stringify(eval(res.bindingCards)) )
                        wData.cardList = eval(res.bindingCards);
                       
                    }
                })

                setTimeout(function() {
                    wAjaxForm("queryVoucherInfo", "", postData, function (rep) {
                        rep = JSON.parse(rep);
                        if (rep.status == 'S') {
                        	//trxAmt：
                        	//mrchntName：
                        	//ordrName
                        	//
                            wData.orderInfo = {
                                trxAmt:rep.trxAmt,
                                mrchntName:rep.mrchntName,
                                ordrName:rep.ordrName,
                                oriTrxId:result.tokenInfo.trxId
                            };
                            
                            $("#home").append(that.templateOrderInfo(wData.orderInfo));//添加银行卡信息页面   比如更多那个功能
                            if(wData.isBindCard == '0' && wData.isUpload == '0' ){
                                console.log("查看cardList值："+JSON.stringify(wData.cardList) )
                                if(wData.cardList){
                                    wData.cardInfo = {
                                        cardBegin: wData.cardList[0].cardBegin,
                                        cardEnd: wData.cardList[0].cardEnd,
                                        cardNo: wData.cardList[0].cardBegin + '******' +  wData.cardList[0].cardEnd,
    
                                    }
                                    wData.isBindCard = '1'
                                    that.$el.append(that.templateNoCard());	//2.首次付款但是可以添加银行卡
                                    $('.tipLeft').html(wData.cardList[0].bankName);//显示银行名称
                                    // let html1 = '<li id="verify"><div>验证码:</div><span class="noLeft"><input id="verifyNo" type="text" placeholder="请输入短信验证码"/></span><span id="getVerify" class="getVerify">获取验证码</span></li>';
                                    // let html2 = '<div id="noCheckList"><div class="agree" style="margin-top:1rem"><span>同意</span><span id="showAgreement" class="color_main mark">《快捷支付服务协议》</span></div><div id="confirm" class="btn disabled">确认付款</div><div class="height_4_rem"></div></div>';
                                    // $(".listInfo").append(html1);
                                    // $("#bindCard").append(html2);
                                    $("#addVerify").append(that.templateAddVerify());
                                    $("#addAgreement").append(that.templateAddAgreement());
                                }else{
                                    wData.cardInfo = {
                                        cardNo: ''
                                    }
                                    that.$el.append(that.templateNoCard());	//2.首次付款但是可以添加银行卡
                                    //2017/11/02 张迪 添加绑卡信息 start
                                    $("#bindCreaditInfo").html('').append(that.templateCreaditInfo()); //1.没有绑卡  完全初始化填写信息的页面
                                    $('#chooseCard').html('').addClass('disabled');
                                    //2017/11/02 张迪 添加绑卡信息 end
                                }
                                
                            }
                            else if(wData.isBindCard == '1' && wData.isUpload == '0' ){ //isBindCard==1已经绑卡：加载的是非首次页面\
                            	console.log("wData.cardInfo:"+JSON.stringify(wData.cardInfo))
                                wData.cardInfo = {
                                    cardBegin: rep.cardBegin,
                                    cardEnd: rep.cardEnd,
                                    cardNo: rep.cardBegin + '******' + rep.cardEnd,
                                }
                                console.log("wData.cardInfo222:"+JSON.stringify(wData.cardInfo))
                                that.$el.append(that.templateHaveCard(wData.cardInfo));//3.非首次付款
                            }
                            else if(wData.isBindCard == '0' && wData.isUpload == '1'){
                                if(rep.bkAcctTp == 'CC' || rep.bkAcctTp == '00'){
                                	//bkAcctTp：贷记卡（信用卡）
                                    wData.cardInfo = {
                                        cardNo: rep.bkAcctNo,
                                        username: rep.cstmrNm,
                                        idCard: rep.iDNo,
                                        phone: rep.mobNo,
                                        iardCvn2: rep.iardCvn2,
                                        iardExprDt: rep.iardExprDt,
                                        cardType : rep.bkAcctTp,
                                        cardName: rep.bankName
                                    }
                                    that.$el.append(that.templateUpCreadit(wData.cardInfo));//4.确认支付页面：贷记卡
                                }
                                else if(rep.bkAcctTp == 'DC' || rep.bkAcctTp == '01') {
                                	//bkAcctTp：借记卡（储蓄卡）
                                    wData.cardInfo = {
                                        cardNo: rep.bkAcctNo,
                                        username: rep.cstmrNm,
                                        idCard: rep.iDNo,
                                        phone: rep.mobNo,
                                        cardName: rep.bankName,
                                        cardType : rep.bkAcctTp
                                    }
                                    that.$el.append(that.templateUpDebit(wData.cardInfo));//5.也是一个支付页面：借记卡
                                }
                            }
                        }else{
                            wTips("请重试");
                        }
                    });
                },100);
                //2017/11/02 张迪 添加绑卡列表信息 end
               
            },function(err) {
                wData.errorMessage = "操作超时,请重试";
                location.hash = "fail";
            })
        },
        //获取验证码
        getVerify: function (e) {
            if(this.bPass){
                return;
            }
            var bOK = $('#getVerify').hasClass('disabled' );
            if(bOK){
                return;
            }
            this.bPass = true;
            objBlur();
            var postData;
            var that = this;
            //console.log(JSON.stringify(window.wData) )
            if(wData.isBindCard == '0' && wData.isUpload == '1'){
                if(wData.cardInfo.cardType == 'CC' ||wData.cardInfo.cardType =='00'){
                    postData={
                        bkAcctNo : $('#bankCode').html().replace(/\s/g, ''),
                        cstmrNm : $('#username').html().replace(/\s/g, ''),
                        iDNo :$('#idCard').html().replace(/\s/g, ''),
                        mobNo : $('#phone').html().replace(/\s/g, ''),
                        bankName : $('#cardName').html().replace(/\s/g, ''),
                        bkAcctTp : '00',
                        iardCvn2 : wData.cardInfo.iardCvn2,
                        iardExprDt : wData.cardInfo.iardExprDt,
                        token : wData.token
                    }
                }
                else if(wData.cardInfo.cardType == 'DC'||wData.cardInfo.cardType== '01'){
                    postData = {
                        bkAcctNo : $('#bankCode').html().replace(/\s/g, ''),
                        cstmrNm : $('#username').html().replace(/\s/g, ''),
                        iDNo :$('#idCard').html().replace(/\s/g, ''),
                        mobNo : $('#phone').html().replace(/\s/g, ''),
                        bankName : $('#cardName').html().replace(/\s/g, ''),
                        bkAcctTp : '01',
                        token : wData.token
                    }
                }
            }
            else if(wData.isBindCard == '1' && wData.isUpload == '0'){
                postData = {
                    cardBegin: wData.cardInfo.cardBegin,
                    cardEnd: wData.cardInfo.cardEnd,
                    token: wData.token
                }
            }
            var _that = this;
            wAjaxForm('quickPayOrder', '', postData, function(result) {
                _that.bPass = false;
                result = JSON.parse(result);
                if(result.bizStsCd == '1'){
                    $('#getVerify').addClass('disabled');
                    $('#chooseCard').addClass('disabled');
                    that.setTimer();
                }else if(result.bizStsCd == '0'){
                    wTips(result.sysRtnDesc);
                }
            } )
            e.preventDefault();
        },
//      handler:function(event){
//      	event.preventDefault();
//      	event.stopPropagation();
//      },
//      OpenMask:function(){
//      	document.body.addEventListener('touchmove',this.handler(),false);
//      	document.body.addEventListener('wheel',this.handler(),false);
//      },
//      CloseMask:function(event){
//      	document.body.removeEventListener('touchmove',this.handler(),false);
//      	document.body.removeEventListener('wheel',this.handler(),false);
//      },
//      StartMask:function(event){
//      	document.body.removeEventListener('touchstart',this.handler(),false);
//      	document.body.removeEventListener('wheel',this.handler(),false);
//      },
        confirm: function(e) {
            if(this.bPass){
                return;
            }
            var bOK = $('#confirm').hasClass('disabled') || this.isEmpty();
            if(bOK){
                return;
            }
            this.bPass = true;
            var postData = {
                token: wData.token,
                smsCode: $('#verifyNo').val()
            }
            var _that = this;
            wAjaxForm('quickPayConfirm', '' ,postData, function(result) {
                _that.bPass = false;
                result = JSON.parse(result);
                if(result.status == 'S'){
                    wData.tip = {
                        img: '<img src="images/icon_success2.png">',
                        text: '您好，您已成功付款<br />￥'+wData.orderInfo.trxAmt
                    }
                    wData.status = 'S';
                }else if(result.status == 'P'){
                    wData.tip = {
                        img: '<img src="images/icon_fail.png">',
                        text: '处理中，请稍候查询'
                    }
                    wData.status = 'P';
                }else if(result.status == 'F'){
                    wTips(result.sysRtnDesc)
                    return;
                }
                location.hash = 'qPayResult';
            })
            e.preventDefault();
        },
        /***张迪 添加银行列表 start  2017/10/09 ***/
        chooseCard: function (e) {
        	$("#chooseCard1 li").not(".block_muen").show();
        	$(".mask_boxclass .block_muen").removeClass('show').addClass('hide');
        	$("#useNewCard").removeClass('hide').addClass('show');
        	$("#chooseCard1").removeClass("mabottom");
        	this.isChooseCard = true;
            var bOK = $('#chooseCard').hasClass('disabled' );
            if(bOK){
                return;
            }
            document.activeElement.blur();
            $('input').blur();
            if($(".listInfo li #mask_box").hasClass("hide")){
                $(".listInfo li #mask_box").removeClass('hide').addClass('show')
            }else if($(".listInfo li #mask_box").hasClass("show")){
                $(".listInfo li #mask_box").removeClass('show').addClass('hide')
            }
            e.preventDefault();
        },
        mask_box: function (e) {
        	if($(e.target).find("#chooseCard1").attr("id")=="chooseCard1"){
        		$(".listInfo li #mask_box").removeClass('show').addClass('hide');
        	}else{
        		return;
        	}
        	e.preventDefault();
        },
        remove_bind:function(e){
        	wData.bankNumber = $("#bankCode").val(); 
//      	var txstBind = confirm("确认解绑？");
//      	if(txstBind==true){
//      		console.log(txstBind)
//      		//$("html").hide();
        		location.hash = "unbind"
//      	}
			e.preventDefault();
        },
        useNewCard:function(e){
    		var that = this;
    	    wData.isBindCard = '0';
    	    wData.selectCardIndex = e.currentTarget.id;
            $('span#cardNo input').val('').removeAttr('disabled');
            $('.tipLeft').html('');//显示银行名称
            $('li#verify').addClass('hide');
            $("#bindCreaditInfo,#bindDebitInfo").html("")
            $("#bindCreaditInfo").append(that.templateCreaditInfo());
            $("#noCheckList").removeClass('show').addClass('hide');
            $('li#useNewCard').addClass('hide');
            $('#cardNo>input').focus();
            $(".listInfo li #mask_box").removeClass('show').addClass('hide');
            e.preventDefault();
        },
        chooseCard1: function (e) {
        	if(this.isChooseCard){
        		//第一次点击
        		var that = this;
	            $(e.currentTarget).show().siblings().not(".block_muen").hide(); 
	            $(".mask_boxclass .block_muen").removeClass('hide').addClass('show');
	            $("#useNewCard").removeClass('show').addClass('hide');
	            $('#bankCode').parents('li').find('.tip').html('');
	            $("#chooseCard1").addClass("mabottom");
	            wData.selectCardIndex = e.currentTarget.id;
	            wData.cardInfo ={};
	            wData.isBindCard = '1';
	            
	            $('#bankCode').val(wData.cardList[wData.selectCardIndex].cardBegin + '******' + wData.cardList[wData.selectCardIndex].cardEnd)
	            wData.cardInfo = {
	                cardBegin: wData.cardList[wData.selectCardIndex].cardBegin,
	                cardEnd: wData.cardList[wData.selectCardIndex].cardEnd
	            }
	            $('span#cardNo input').attr('disabled','disabled');
	            $('.tipLeft').html(wData.cardList[wData.selectCardIndex].bankName);//显示银行名称
	            $("#bindCreaditInfo").html('');
	            $("#bindDebitInfo").html('');
	            $("#noCheckList").removeClass('hide').addClass('show');
	            $('li#verify').removeClass('hide').addClass('show');
	            $('li#useNewCard').removeClass('hide').addClass('show');
	            this.isChooseCard = false;
        	}else{
//      		在点击处(chooseCard方法处)做了处理,下面的代码没有用了
        		$("#chooseCard1 li").not(".block_muen").show();
        		$(".mask_boxclass .block_muen").removeClass('show').addClass('hide');
        		$("#useNewCard").removeClass('hide').addClass('show');
        		$("#chooseCard1").removeClass("mabottom");
        		this.isChooseCard = true;
        	}
            e.preventDefault();
           
            
                
        },
        choosecard_confirm:function(e){
        	$(".mask_boxclass .block_muen").removeClass('show').addClass('hide');
        	$(".listInfo li #mask_box").removeClass('show').addClass('hide');
        	e.preventDefault();
        },
        /***张迪 添加银行列表 end    ***/

        /***张迪 为'支持银行列表及限额'添加事件  start  2017/10/11 ***/
        limitList: function (e){
            
            this.$el.append(this.templateBankLimit());
            App.title("银行限额列表");
            $("#head_back").show();
            var postData = {
                "token": wData.token
                
            };
            wAjaxForm('queryBankList', '', postData, function(result){
                result = JSON.parse(result);
                if(result.sysRtnCd != 'S0001'){
                        wTips(result.sysRtnDesc);
                }
                else{
                    wData.bankLimitPlaceList = result.bankLimitPlaceList;
                    var tradeDetailStr = '';
                    for (var i = 0; i < wData.bankLimitPlaceList.length; i++) {
                        //00 贷记卡    01 借记卡
                        if(wData.bankLimitPlaceList[i].cardType == '00'){
                            wData.bankLimitPlaceList[i].cardType = '信用卡'
                        }
                        else if(wData.bankLimitPlaceList[i].cardType == '01'){
                            wData.bankLimitPlaceList[i].cardType = '储蓄卡'
                        }
                        tradeDetailStr+=
                            '<tr class="tableTr">' +
                            '<td class="tableTh">' + wData.bankLimitPlaceList[i].bankName + '</td>' +
                            '<td class="tableTh">' + wData.bankLimitPlaceList[i].cardType + '</td>' +
                            '<td class="tableTh">' + wData.bankLimitPlaceList[i].amtMinSingle + '</td>' +
                            '<td class="tableTh">' + wData.bankLimitPlaceList[i].amtMaxSingle + '</td>' +
                            '<td class="tableTh">' + wData.bankLimitPlaceList[i].amtMaxDay + '</td>' +
                            '</tr>';
                            
                        }
                    $(".bankLimitTbody").after(tradeDetailStr);
                }
                
            });

            e.preventDefault();
        },
        //返回
        closeBankLimit: function (e) {
            $("#head_back").hide();
            $("#bankLimit").remove();
            App.title("快捷支付");
            e.preventDefault();
        },
        back: function (e) {
          	$("#head_back").hide();
            $("#bankLimit").remove();
            
            if (!$("#check_Icon").hasClass("check")) {
                $("#check_Icon").removeClass("notCheck").addClass("check");
            }
            $("#agreement").remove();
            
            App.title("快捷支付");
            e.preventDefault();
        },
        /***张迪 为'支持银行列表及限额'添加事件  end    2017/10/11 ***/

        //银行卡号校验
        bankTest: function() {
            /******2017/10/11 张迪 当银行卡号栏位失焦时查卡bin start*******/
            var that = this;
            var data = $('#bankCode').val();
            var bankNames = $('.tipLeft').html();
            if(data == '' && bankNames != ''){
                $('.tipLeft').html('');
            }
            var result1 = this.luhmCheck(data);
            $('#bankCode').parents('li').find('.tip').html(result1.error);
            if(result1.success != false){
                var postData = {
                    "token": wData.token,
                    'cardNo': $('#bankCode').val()
                };
                
                wAjaxForm('queryCardBin', '', postData, function(result){
                    result = JSON.parse(result);
                    if(result!==''){
                        wData.cardInfo = {
                            cardNo: $('#bankCode').val(),
                            cardType: result.cardType,
                            cardName: result.cardName
                        }
                        
                        $('.tipLeft').html(wData.cardInfo.cardName);//显示银行名称
                        if(result.cardType){
                            
                            
                            if(result.cardType == 'DC'){
                                $("#bindCreaditInfo").html('');
                                if($("#bindDebitInfo").html() == ''){
                                    $("#bindDebitInfo").append(that.templateDebitInfo());
                                    $("#noCheckList").removeClass('show').addClass('hide');
                                }
								
                            }
                            else if(result.cardType == 'CC'){
                                $("#bindDebitInfo").html('');
                                if($("#bindCreaditInfo").html() == ''){
                                    $("#bindCreaditInfo").append(that.templateCreaditInfo());
                                    $("#noCheckList").removeClass('show').addClass('hide');
                                }
								
                            }
                        }
                        else{
                            wTips('当前不支持卡类型');
                        }
                    }
                    else{
                        wTips('系统异常！')
                    }
                    
                });
                return result1.success;
            }
          /******2017/10/11 张迪 当银行卡号栏位失焦时查卡bin end*******/
        },
        
        //显示协议内容
        showAgreement: function (e) {
        	$("#head_back").show();
            this.$el.append(this.templateAgreement());
            App.title("快捷支付服务协议");
            e.preventDefault();
        },
        //阅读并接受协议
        closeAgreement: function (e) {
        	$("#head_back").hide();
            if (!$("#check_Icon").hasClass("check")) {
                $("#check_Icon").removeClass("notCheck").addClass("check");
            }
            $("#agreement").remove();
            App.title("快捷支付");
            e.preventDefault();
        },
        //展开订单信息
        more: function (e) {
            if ($("#more").html() == "收起") {
                $("#order").css({"height": "2.6rem"});
                $("#more").html("更多");
            }
            e.preventDefault();
        },
        destroy: function () {
            this.undelegateEvents();
            this.$el.html("");
            $('#home').html('');
            $("#head_back").show();
            if (this.Interval != -1) {
                clearInterval(this.Interval);
                this.Interval = -1;
                $("#getVerify").html("免费获取").removeClass("color_9C9B9B").addClass("color_63b4ff");
            }
            delete this;
        },
        
        luhmCheck: function (bankno){
            if(bankno.length==''){
                return {"success": false, "error": '银行卡不能为空'};
            }
            if (bankno.length < 14 || bankno.length > 19) {
                return {"success": false, "error": '银行卡长度有误'};
            }
            var num = /^\d*$/; //全数字
            if (!num.exec(bankno)) {
                return {"success": false, "error": '卡号必须为数字'};
            }
  
            var lastNum=bankno.substr(bankno.length-1,1);//取出最后一位（与luhm进行比较）
            var first15Num=bankno.substr(0,bankno.length-1);//前15或18位
            var newArr=new Array();
            for(var i=first15Num.length-1;i>-1;i--){ //前15或18位倒序存进数组
                newArr.push(first15Num.substr(i,1));
            }
            var arrJiShu=new Array(); //奇数位*2的积 <9
            var arrJiShu2=new Array(); //奇数位*2的积 >9
            var arrOuShu=new Array(); //偶数位数组
            for(var j=0;j<newArr.length;j++){
                if((j+1)%2==1){//奇数位
                    if(parseInt(newArr[j])*2<9)
                        arrJiShu.push(parseInt(newArr[j])*2);
                    else
                        arrJiShu2.push(parseInt(newArr[j])*2);
                }
                else //偶数位
                    arrOuShu.push(newArr[j]);
            }
            var jishu_child1=new Array();//奇数位*2 >9 的分割之后的数组个位数
            var jishu_child2=new Array();//奇数位*2 >9 的分割之后的数组十位数
            for(var h=0;h<arrJiShu2.length;h++){
                jishu_child1.push(parseInt(arrJiShu2[h])%10);
                jishu_child2.push(parseInt(arrJiShu2[h])/10);
            }
            var sumJiShu=0; //奇数位*2 < 9 的数组之和
            var sumOuShu=0; //偶数位数组之和
            var sumJiShuChild1=0; //奇数位*2 >9 的分割之后的数组个位数之和
            var sumJiShuChild2=0; //奇数位*2 >9 的分割之后的数组十位数之和
            var sumTotal=0;
            for(var m=0;m<arrJiShu.length;m++){
                sumJiShu=sumJiShu+parseInt(arrJiShu[m]);
            }
            for(var n=0;n<arrOuShu.length;n++){
                sumOuShu=sumOuShu+parseInt(arrOuShu[n]);
            }
            for(var p=0;p<jishu_child1.length;p++){
                sumJiShuChild1=sumJiShuChild1+parseInt(jishu_child1[p]);
                sumJiShuChild2=sumJiShuChild2+parseInt(jishu_child2[p]);
            }
    
            sumTotal=parseInt(sumJiShu)+parseInt(sumOuShu)+parseInt(sumJiShuChild1)+parseInt(sumJiShuChild2);
    
            var k= parseInt(sumTotal)%10==0?10:parseInt(sumTotal)%10;
            var luhm= 10-k;
            if(lastNum==luhm){
                return {"success": true, "error": ''};
            }
            else{
                return {"success": false, "error": '银行卡号不符合规范'};
            }

        },
        isEmpty: function(event) {
            var _el = $('.listInfo').find('input');
            for(var i = 0; i<_el.size();i++){
                if(_el.eq(i).val()==''){
                    this.$isEmpty = true;
                    break;
                }else{
                    this.$isEmpty = false;
                }
            }
            if(!this.$isEmpty){
                $('#next').removeClass('disabled');
                $('#confirm').removeClass('disabled');

            }
            else{
                $('#next').addClass('disabled');
                $('#confirm').addClass('disabled');
            }
            return this.$isEmpty;
        },
        limitLen: function(event) {
            var lengths = 0;
            var id = event.target.id
            if(id == 'bankCode'){
                lengths = 19
                nonNumeric($('#'+id));
            }
            else if(id == 'verifyNo'){
                lengths = 6;
            }
            limitLength($('#'+id),lengths);
            this.isEmpty();
        },
        setTimer: function() {
            var sec = 60;
            var str = '';
            var timer = setInterval(function() {
                sec--;
                if(sec==0){
                    clearInterval(timer);
                    str = '获取验证码';
                    $('#getVerify').removeClass('disabled');
                    $('#chooseCard').removeClass('disabled');
                    
                }else{
                    str = sec+'s重新获取';
                }
                $('#getVerify').html(str);
            },1000);
        },


        // 2017/11/03  张迪改造的方法  start
        getVerify01: function (e) {
            e.preventDefault();
            if(this.bPass){
                return;
            }
            var  bOK = $('#getVerify01').hasClass('disabled' ) || !this.nameTest() || !this.phoneNumTest() || !this.idCardTest();
            if(wData.cardInfo.cardType == 'CC'||wData.cardInfo.cardType == '00'){
                bOK = !this.cvv2NumTest() || !this.dateNumTest();
            }
            if(bOK){
                return;
            }
            this.bPass = true;
            objBlur();
            var postData={};
            var that = this;
            if(wData.isBindCard == '0' && wData.isUpload == '0'){
                postData.bkAcctNo = $('#bankCode').val().replace(/\s/g, '');
                postData.cstmrNm = $('#username').val();
                postData.iDNo = $('#idCard').val();
                postData.mobNo = $('#phone').val();
                postData.bankName = $('.tipLeft').html().replace(/\s/g, '');
                postData.token = wData.token;
                if(wData.cardInfo.cardType == 'CC' ||wData.cardInfo.cardType =='00' ){
                    postData.bkAcctTp = '00';
                    postData.iardCvn2 = $('#iardCvn2').val();
                    postData.iardExprDt = $('#iardExprDt').val().substring(0,2)+'/'+$('#iardExprDt').val().substring(2);
                }
                else if(wData.cardInfo.cardType == 'DC'||wData.cardInfo.cardType== '01'){
                    postData.bkAcctTp = '01';
                }
            }
            var _that = this;
            wAjaxForm('quickPayOrder', '', postData, function(result) {
                result = JSON.parse(result);
                _that.bPass = false;
                if(result.bizStsCd == '1'){
                    $('#getVerify01').addClass('disabled');
                    $('#chooseCard').addClass('disabled');
                    that.setTimer01();
                }else if(result.bizStsCd == '0'){
                    wTips(result.sysRtnDesc);
                }

            }, function(result){
                wTips("获取短信失败");
                _that.resetGetVerify01();
            });
        },
        resetGetVerify01:function(){
            // 恢复按钮点击
            this.bPass = false;
            $('#getVerify01').removeClass('disabled');
            $('#chooseCard').removeClass('disabled');
        },
        nameTest: function(event) {
            var data = $('#username').val();
            var result = wCheck(data,'username');
            $('#username').parents('li').find('.tip').html(result.error)
            return result.success
        },
        idCardTest: function() {
            var data = $('#idCard').val();
            var result = wCheck(data,'idCard');
            $('#idCard').parents('li').find('.tip').html(result.error)
            return result.success
        },
        phoneNumTest: function() {
            var data = $('#phone').val();
            var result =wCheck(data,'mobilePhone');
            $('#phone').parents('li').find('.tip').html(result.error)
            return result.success;
        },
        cvv2NumTest: function() {
            var data = $('#iardCvn2').val();
            var result = wCheck(data,'cvv2');
            $('#iardCvn2').parents('li').find('.tip').html(result.error)
            return result.success
        },
        dateNumTest: function() {
            var data = $('#iardExprDt').val();
            var result = wCheck(data,'dateNum');
            $('#iardExprDt').parents('li').find('.tip').html(result.error)
            return result.success;
        },
        confirm01: function(e) {
            if(this.bPass){
                return;
            }
            var  bOK = $('#confirm01').hasClass('disabled' ) || !this.nameTest() || !this.phoneNumTest() || !this.idCardTest();
            if(wData.cardInfo.cardType == 'CC'||wData.cardInfo.cardType == '00'){
                bOK = !this.cvv2NumTest() || !this.dateNumTest();
            }
            if(bOK){
                return;
            }
            this.bPass = true;
            var postData = {
                token: wData.token,
                smsCode: $('#verifyNo01').val()
            }
            var _that = this;
            wAjaxForm('quickPayConfirm', '' ,postData, function(result) {
                _that.bPass = false;
                result = JSON.parse(result);
                if(result.status == 'S'){
                    wData.tip = {
                        img: '<img src="images/icon_success2.png">',
                        text: '您好，您已成功付款<br />￥'+wData.orderInfo.trxAmt
                    }
                    wData.status = 'S';
                }else if(result.status == 'P'){
                    wData.tip = {
                        img: '<img src="images/icon_fail.png">',
                        text: '处理中，请稍候查询'
                    }
                    wData.status = 'P';
                }else if(result.status == 'F'){
                    wTips(result.sysRtnDesc)
                    return;
                }
                location.hash = 'qPayResult';
            })
            e.preventDefault();
        },
        isEmpty01: function(event) {
            var _el = $('.listInfo').find('input');
            for(var i = 0; i<_el.size();i++){
                if(i != 1){//循环input 不等于input#verifyNo
                    if(_el.eq(i).val()==''){
                        this.$isEmpty01 = true;
                        break;
                    }else{
                        this.$isEmpty01 = false;
                    }
                }
            }
            if(!this.$isEmpty01){
                // $('#next').removeClass('disabled');
                $('#confirm01') && $('#confirm01').removeClass('disabled');
            }
            else{
                // $('#next').addClass('disabled');
                $('#confirm01') && $('#confirm01').addClass('disabled');
            }
            return this.$isEmpty01;
        },
        limitLen01: function(event) {
            //debugger;
            var lengths = 0;
            var id = event.target.id
            if(id == 'bankCode'){
                lengths = 19
                nonNumeric($('#'+id));
            }
            else if(id == 'username'){
                lengths = 20;
                limitName($('#'+id),lengths);
                this.isEmpty();
                return;
            }
            else if(id == 'verifyNo01'){
                lengths = 6;
            }else if(id == 'idCard'){
                lengths = 18;
            }
            else if(id == 'iardExprDt'){
                lengths = 4;
            }
            else if( id == 'iardCvn2'){
                lengths = 3;
            }
            else if( id == 'phone'){
                lengths = 11;
            }
            else if( id== 'verifyNo01'){
                lengths = 6;
            }
            limitLength($('#'+id),lengths);
            this.isEmpty01();
        },
        setTimer01: function() {
            var sec = 60;
            var str = '';
            var timer = setInterval(function() {
                sec--;
                if(sec==0){
                    clearInterval(timer);
                    str = '获取验证码';
                    $('#getVerify01').removeClass('disabled');
                    $('#chooseCard').removeClass('disabled');
                }else{
                    str = sec+'s重新获取';
                }
                $('#getVerify01').html(str);
            },1000);
        },
    });
});